package com.hrm.service.impl;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.hrm.dao.UserLogMapper;
import com.hrm.entity.UserLog;
import com.hrm.service.UserLogService;
import com.hrm.util.Page;

public class UserLogServiceImpl implements UserLogService {
	private static final Log log = LogFactory.getLog(UserLogServiceImpl.class); 
	@Autowired
	private UserLogMapper userLogMapper;
	
	public UserLogMapper getUserLogMapper() {
		return userLogMapper;
	}

	public void setUserLogMapper(UserLogMapper userLogMapper) {
		this.userLogMapper = userLogMapper;
	}
	
	public List<UserLog> getUserLogs() {
		log.info("****** Do method getUserLogs() begin,no params info.");
		List<UserLog> userLogs=userLogMapper.selectAllUserLog();
		log.info("****** Do method getRoles() end,return info ==== [ List<UserLog>="+userLogs+" ]");
		return userLogs;
	}
	public UserLog getUserLogById(long id) {
		log.info("****** Do method getUserLogById(long id) begin,params info ==== [ id="+id+" ]");
		UserLog userLog =  userLogMapper.selectUserLogById(id);
		log.info("****** Do method getUserLogById(long id) end,return info ==== [ UserLog="+userLog+" ]");
		return userLog;
	}

	public int addUserLog(UserLog userLog) {
		log.info("****** Do method addUserLog(UserLog userLog) begin,params info ==== [ userLog="+userLog+" ]");
		int cnts=-1;
		cnts= userLogMapper.insertUserLog(userLog);
		log.info("****** Do method addUserLog(UserLog userLog) end,return info ==== [ int="+cnts+" ]");
		return cnts;
	}

	public int updateUserLog(UserLog userLog) {
		log.info("****** Do method updateUserLog(UserLog userLog) begin,params info ==== [ userLog="+userLog+" ]");
		int cnts=-1;
		cnts= userLogMapper.updateUserLog(userLog);
		log.info("****** Do method updateUserLog(UserLog userLog) end,return info ==== [ int="+cnts+" ]");
		return cnts;
	}

	public int deleteUserLogById(long id) {
		log.info("****** Do method deleteUserLogById(long id) begin,params info ==== [ id="+id+" ]");
		int cnts=-1;
		cnts= userLogMapper.deleteUserLogById(id);
		log.info("****** Do method deleteUserLogById(long id) end,return info ==== [ int="+cnts+" ]");
		return cnts;
	}
	

	public List<UserLog> getUserLogs(Page page) {
		log.info("****** Do method getUserLogs(Page page) begin,params info ==== [page="+page+"]");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("currentStart", page.getCurrentStart()-1);
		map.put("currentEnd", page.getCurrentStart()+page.getPagesize()-1);
		List<UserLog> userLogs = userLogMapper.selectUserLogByMap(map);
		log.info("****** Do method getUserLogs(Page page) end,return info ==== [ List<UserLog>="+userLogs+" ]");
		return userLogs;
	}

	public int getUserLogCounts() {
		log.info("****** Do method getUserLogCounts() begin,no params info.");
		int cnts=-1;
		cnts= userLogMapper.getAllUserLogCounts();
		log.info("****** Do method getUserLogCounts() end,return info ==== [ int="+cnts+" ]");
		return cnts;
	}

	public int deleteUserLogById(String ids) {
		log.info("****** Do method deleteUserLogById(String ids) begin,params info ==== [ ids="+ids+" ]");
		Map<String,Object> map = new HashMap<String,Object>();
		String[] tmp=ids.split(",");
		Integer[] tids = new Integer[tmp.length];
		for(int i=0;i<tmp.length;i++){
			tids[i]=Integer.parseInt(tmp[i]);
		}
		List<Integer> userLogs=Arrays.asList(tids);
		map.put("ids", userLogs);
		int cnts=-1;
		cnts=userLogMapper.deleteUserLogByMap(map);
		log.info("****** Do method deleteUserLogById(String ids) end,return info ==== [ int="+cnts+" ]");
		return cnts;
	}

	public List<UserLog> getUserLogsByType(Page page,String type) {
		log.info("****** Do method getConfigItems(Page page,String type) begin,params info ==== [page="+page+",type="+type+"]");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("currentStart", page.getCurrentStart()-1);
		map.put("currentEnd", page.getCurrentStart()+page.getPagesize()-1);
		map.put("configType", type);
		List<UserLog> userLogs = userLogMapper.selectUserLogByMap(map);
		log.info("****** Do method getConfigItems(Page page,String type) end,return info ==== [ List<UserLog>="+userLogs+" ]");
		return userLogs;
	}

	public int getUserLogCountsByType(String type) {
		log.info("****** Do method getConfigItemsCountsByType() begin,no params info.");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("configType", type);
		int cnts=-1;
		cnts= userLogMapper.getUserLogCountsByMap(map);
		log.info("****** Do method getConfigItemsCountsByType() end,return info ==== [ int="+cnts+" ]");
		return cnts;
	}

}
